package com.des1gn.serviceb.schedule;

import com.des1gn.serviceb.config.MybatisContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @ClassName MybatisSchedule
 * @Description TODO
 * @Author Des1gn
 * @Version 1.0
 **/
@EnableScheduling
@Component
@Slf4j
@RequiredArgsConstructor
public class MybatisSchedule {

    private final MybatisContext mybatisContext;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void reloadMapperCache(){
      log.debug("mybatis mapper cache reload start");
        try {
            mybatisContext.reloadMapper();
        } catch (IOException e) {
            log.error("mybatis mapper cache reload error {}",e);
            throw new RuntimeException(e);
        }
        log.debug("mybatis mapper cache reload end");
    }

}
